<?php
//图形验证码
function verify(){
    $config =    array(    
    'fontSize'    =>    30,    // 验证码字体大小    
    'length'      =>    4,     // 验证码位数    
    'useNoise'    =>    false, // 关闭验证码杂点
    );
    return $config;
}

//获取客户端真实IP
function get_client_ip_user($type = 0) {
   if (getenv("HTTP_CLIENT_IP"))  
        $ip = getenv("HTTP_CLIENT_IP");  
    else if(getenv("HTTP_X_FORWARDED_FOR"))  
        $ip = getenv("HTTP_X_FORWARDED_FOR");  
    else if(getenv("REMOTE_ADDR"))  
        $ip = getenv("REMOTE_ADDR");  
    else $ip = "Unknow";  
    return $ip;  
}
//隐藏手机号码中间四位
function hidtel($phone){
    $IsWhat = preg_match('/(0[0-9]{2,3}[\-]?[2-9][0-9]{6,7}[\-]?[0-9]?)/i',$phone); //固定电话
    if($IsWhat == 1){
        return preg_replace('/(0[0-9]{2,3}[\-]?[2-9])[0-9]{3,4}([0-9]{3}[\-]?[0-9]?)/i','$1****$2',$phone);
    }else{
        return  preg_replace('/(1[3578]{1}[0-9])[0-9]{4}([0-9]{4})/i','$1****$2',$phone);
    }
}

    //合并播放次数
    function get_play_count($list){
         foreach($list as $k=>$v){
                $video_id = $v['id'];
                $map['id'] = $video_id;
                $video_info = D('VideoHouse')->get_one($map);
                $list[$k]['play'] = $video_info['play_amount']+$video_info['push_play'];
            }
            return $list;

    }
    //id获取用户信息
    function get_user_info($id){
        $map['id'] = $id;
        $user_info = D('User')->get_one($map);
        // return D('User')->_sql();
        return $user_info;
    }
  /**
     * 节目id换节目名称
     */
     function get_program_name($id){
        $map['id'] = $id;
        $name = D('Program')->get_one($map);
        return $name['pname'];
    }

     /**
     * 分类id换分类名称
     */
     function get_cate_name($id){
        $map['id'] = $id;
        $name = D('Category')->get_one($map);
        return $name['cate_name'];
    }

    /**
     * 主持人id换支持人名称
     */
     function get_host_name($id){
        $map['id'] = $id;
        $name = D('Host')->get_one($map);
        return $name['name'];
    }

       /**
     * 主持人id换支持人touxiang
     */
     function get_host_pic($id){
        $map['id'] = $id;
        $name = D('Host')->get_one($map);
        return $name['pic'];
    }

        /**
     * 标签id换标签名
     */
    function get_lable_name($id){
        $map['id'] = $id;
        $name = D('Label')->get_one($map);
        return $name['name'];
    }


//点赞+1
//@ type: 1:文章  2：视频   3：评论
function praise_push_count($type,$id){
    $map['id'] = $id;
    if($type==1){
        $r= D('NewsHouse')->set_praise_int($map);
    }else if($type==2){
        $r= D('VideoHouse')->set_praise_int($map);
        // echo D('VideoHouse')->_sql();die;
    }else if($type==3){
        $r= D('Comment')->set_praise_int($map);
    }else if($type==4){
        $r= D('Figure')->set_praise_int($map);
    }else if($type==5){
        $r= D('Answer')->set_praise_int($map);
    }else if($type==6){
        $r= D('PlatformCommentary')->set_praise_int($map);
    }else if($type==7){
        $r= D('Depth')->set_praise_int($map);
    }else if($type==8){
        $r= D('CircleOpinion')->set_praise_int($map);
    }else if($type==9){
        $r= D('CircleAnnounce')->set_praise_int($map);
    }

    //echo D('Depth')->_sql();die;
    return $r;
}

//字符串截取
function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)    
{    $l = mb_strlen($str,'UTF8'); 
    if($l>$length){
    if(function_exists("mb_substr"))  
    {    
        if($suffix)    
            return mb_substr($str, $start, $length, $charset).'...'; 
        else  
            return mb_substr($str, $start, $length, $charset).'...';    
    }    
    elseif(function_exists('iconv_substr'))   
    {    
        if($suffix)    
            return iconv_substr($str,$start,$length,$charset).'...';     
        else  
            return iconv_substr($str,$start,$length,$charset).'...';
    }    
    $re['utf-8']   = "/[x01-x7f]|[xc2-xdf][x80-xbf]|[xe0-xef]  
    [x80-xbf]{2}|[xf0-xff][x80-xbf]{3}/";    
    $re['gb2312'] = "/[x01-x7f]|[xb0-xf7][xa0-xfe]/";    
    $re['gbk']    = "/[x01-x7f]|[x81-xfe][x40-xfe]/";    
    $re['big5']   = "/[x01-x7f]|[x81-xfe]([x40-x7e]|xa1-xfe])/";    
    preg_match_all($re[$charset], $str, $match);    
    $slice = join("",array_slice($match[0], $start, $length));    
    if($suffix) return $slice;     
    return $slice;
    }else{
        return $str;
    }
}  